<template>
  <!-- //TODO: 修改样式 -->
  <div>
    <div v-for="(item, index) in list" :key="index" class="reply">
      <div class="comments">
        <div class="info">
          <a-avatar
            slot="avatar"
            :src="item.avatar"
          />
          <span style="color: #2d9aff"> {{ item.nickname }} </span
          ><span>回复</span>
          <span style="color: #2d9aff">{{ item.replyTo }}</span>
          <el-divider direction="vertical"></el-divider>
          <span style="margin-left: 5px"> {{ item.content }}</span>
        </div>

        <div slot="action" class="action">
          <el-button
            type="text"
            @click="toParent(item)"
            class="el-icon-message"
          >
            回复
          </el-button>
          <div class="el-icon-date">
            {{ momentFormat(item.createTime) }}
          </div>
          <br />
        </div>
      </div>
      <div v-if="item.childList" class="reply">
        <list
          :list="item.childList"
          :comment="item"
          v-bind="$attrs"
          v-on="$listeners"
        ></list>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
moment.locale('zh-cn')

export default {
  name: "List",
  props: {
    list: Array,
  },
  data() {
    return {};
  },
  methods: {
    //获取父类的方法
    toParent(item) {
      this.$emit("showCommentInput", item);
    },
    momentFormat(dateStr) {
      return moment(new Date(dateStr)).startOf('millisecond').fromNow()
    }
  },
};
</script>

<style lang="less" scoped>
.reply {
  text-indent: 60px;
  font-size: 15px;

  .comments {
    display: flex;
    justify-content: space-between;
    width: 100%;


    .action {
      display: flex;
      flex-flow: column;
      align-items: flex-end;
      margin-right: 30px;
    }
  }
}
</style>

